//
//  HttpClientComponent.h
//  UniversalArchitecture
//
//  Created by issuser on 12-10-29.
//  Copyright (c) 2012年 issuser. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "FFEncryptInterceptor.h"

/*
 * 无网络连接时返回的
 */
#define FFCNetworkErrorCode        256
#define FFCNetworkErrorMessage     @"网络连接异常"

/**
 请求成功block
 */
typedef void (^RequestSuccessBlock)(NSString *responseString);
/**
 请求失败block
 */
typedef void (^RequestFailureBlock)(NSError *error);

/**
 请求成功block
 */
typedef void (^RequestUploadSuccessBlock)(id object);


@interface FFHttpClientComponent : NSObject

/**
 *  请求响应头
 */
@property (nonatomic, strong) NSDictionary *responseHeaders;

/**
 *  请求响应原始数据
 */
@property (nonatomic, strong) NSData *responseData;
/**
 *  请求响应字符串
 */
@property (nonatomic, strong) NSString *responseString;
/**
 *  请求响应字典
 */
@property (nonatomic, strong) NSDictionary *responseDictionary;

/**
 * 是否开启调试日志
 *
 *  @param enable YES:开启日志；NO：关闭日志
 */

- (void)enableDebugLogging:(BOOL)enable;

/**
 * 设置请求超时时间，单位：秒
 * 使用提示：此方法连同设置url缓存时长，设置通用参数一致，可放在BaseBiz中做设置
 *
 *  @param timeoutInterval 超时时间
 */
- (void)setRequestTimeoutInterval:(NSTimeInterval)timeoutInterval;


/**
 * 设置是否使用缓存，设为 NO 时强制请求网络
 *
 *  @param use 是否使用缓存
 */
- (void)setUseCache:(BOOL)use;

/**
 * 添加http请求头
 *
 *  @param dictionary 需要添加的额外请求头字典
 */
- (void)addRequestHeaders:(NSDictionary *)dictionary;

/**
 * 获取http请求返回头
 *
 *  @return 返回头
 */
-(NSDictionary *)getResponseHeaders;


/**
 * 发送GET请求
 *
 *  @param url            网络请求地址
 *  @param params         请求消息字典，无须转换为json
 *  @param successHandler 请求成功回调
 *  @param failureHandler 请求失败回调
 */
- (void)get:(NSString *)url
     params:(NSDictionary *)params
encryptInterceptor:(FFEncryptInterceptor *)interceptor
    success:(RequestSuccessBlock)successHandler
    failure:(RequestFailureBlock)failureHandler;


/**
 * 发送POST请求
 *
 *  @param url            网络请求地址
 *  @param params         请求消息字典，无须转换为json
 *  @param successHandler 请求成功回调
 *  @param failureHandler 请求失败回调
 */
- (void)post:(NSString *)url
      params:(NSDictionary *)params
encryptInterceptor:(FFEncryptInterceptor *)interceptor
     success:(RequestSuccessBlock)successHandler
     failure:(RequestFailureBlock)failureHandler;


/**
 * 发送POST请求
 *
 *  @param url            网络请求地址
 *  @param params         请求消息字典，无须转换为json
 *  @param successHandler 请求成功回调
 *  @param failureHandler 请求失败回调
 */

- (void)sendPOSTRequestWithUrl:(NSString *)url
                        params:(id)params
                       success:(RequestSuccessBlock)successHandler
                       failure:(RequestFailureBlock)failureHandler;


/**
 * 发送GET请求
 *
 *  @param url            网络请求地址
 *  @param params         请求消息字典，无须转换为json
 *  @param successHandler 请求成功回调
 *  @param failureHandler 请求失败回调
 */


- (void)sendGETRequestWithUrl:(NSString *)url
                       params:(NSDictionary *)params
                      success:(RequestSuccessBlock)successHandler
                      failure:(RequestFailureBlock)failureHandler;

- (void)uploadFilesWithUrl:(NSString *)url
                parameters:(NSDictionary *)parameters
                  fileData:(NSData *)fileData
                   success:(RequestUploadSuccessBlock)successHandler
                   failure:(RequestFailureBlock)failureHandler;



- (void)uploadFilesWithUrlV2:(NSString *)url
                  parameters:(NSDictionary *)parameters
                    fileData:(NSData *)fileData
                     success:(RequestUploadSuccessBlock)successHandler
                     failure:(RequestFailureBlock)failureHandler;

@end

